<?php
/**
 * BusBase
 * Created by Veyron
 * motto:现在的拼搏 为了更好的明天
 * day:  2020/2/9
 * Time: 16:11
 */

namespace app\common\business;


use app\common\implement\Common;
use think\Exception;

class BusBase
{
    /**
     * 添加规格值
     * @param $data
     * @return bool|mixed
     */
    public function add($data){
        $data['status'] = config('status.mysql.table_normal');
        try {
            $this->model->save($data);
        }catch (\Exception $e){
            //记录日志
            return false;
        }

        return $this->model->id;
    }

    /**
     * 根据ID获取分类记录
     * @param $id
     * @return array|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getById($id){
        $result = $this->model->find($id);
        if(!$result){
            return [];
        }
        $result = $result->toArray();
        return $result;
    }
    /**
     * 修改状态
     * @param $id
     * @param $status
     * @return bool
     * @throws Exception
     */
    public function status($id,$data){
        //查询记录是否存在
        $res = $this->getById($id);
        if(!$res){
            throw new Exception('不存在该条记录');
        }
//        $data = [
//            'status' => $status
//        ];
        try{
            $res = $this->model->updateById($id,$data);
        }catch (\Exception $e){
            //记录日志
            return false;
        }
        return $res;
    }
    public function getInByIds($orderIds,$conition=[]){
        try {
            $result = $this->model->getInByIds(['order_id',$orderIds], $conition);
        }catch (\Exception $e){
            return [];
        }
        if(!$result){
            return [];
        }
        return $result->toArray();
    }
}
